package plugin.app;

import org.pf4j.DefaultPluginManager;
import org.pf4j.PluginManager;
import plugin.api.Greeting;

import java.nio.file.Paths;
import java.util.List;

public class Boot {
    public static void main(String[] args) {
        // jar插件管理器
        PluginManager pluginManager = new DefaultPluginManager(Paths.get("E:\\pro\\pf4j-demo\\plugins"));
        // 加载指定路径插件
        pluginManager.loadPlugins();
        // 启动指定插件(也可以加载所有插件)
        pluginManager.startPlugins();

        // 执行插件
        List<Greeting> greetings = pluginManager.getExtensions(Greeting.class);
        System.out.println("greetings : "+greetings.size());
        for (Greeting greeting : greetings) {
            System.out.println(">>> " + greeting.getGreeting());
        }

        // 停止并卸载指定插件
        pluginManager.stopPlugin("welcome-plugin");
        pluginManager.unloadPlugin("welcome-plugin");

    }
}
